package company.tree;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Ntree589 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String input = sc.nextLine();
        String[] split = input.split("null");
        Ntree ntree = new Ntree();
        for (int i = 0; i < split.length; i++) {
            List<Integer> singelList = new ArrayList<>();
            String[] split1 = split[i].split(",");
            for (int j = 0; j < split1.length; j++) {
                if (split1[j].equals("")) {
                    continue;
                }
                singelList.add(Integer.parseInt(split1[j]));
            }
            ntree.insertNTree(ntree.root,singelList);
        }
        preorder(ntree.root);
    }

    public static List<Integer> preorder(NTreeNode root) {
        List<Integer> res = new ArrayList<>();
        if (root == null) {
            return res;
        }
        res.add(root.getValue());
        for (NTreeNode node : root.getNodeList()) {
            res.addAll(preorder(node));
        }
        return res;
    }
}
